<?php
class AdminTopNavWidget  extends CWidget{
    
	//输出字符串
	private $out = '';
    
    private $controller= '';
    
    private $action= '';

	public function init(){
        $this->controller = Yii::app()->controller->id;  
        $this->action = Yii::app()->controller->action->id; 
	}

	public function run(){
        $this->generateTopNav();
		echo $this->out;
	}
    
    public function configNavItem(){
        $loginUserName = Yii::app()->admin->name;
        $item = array(
            array('title'=>'退出('.$loginUserName.')','url'=>Yii::app()->createUrl('admin/default/logout'),'active'=>''),
        );
        return $item;
    }
    
    public function generateTopNav(){
        $adminUrl = yii::app()->createUrl('/site/index');
        $item = $this->configNavItem();
        $itemString = '';
        $titleString = CHtml::encode(Yii::app()->name);
        $descriptionString = CHtml::encode(Yii::app()->params['description']);
        
        foreach ($item as $k=>$v){
            $itemString .= <<<ITEM
                    <li style='line-height:8px' class="{$v['active']}">
                        <a class="nav-item" href="{$v['url']}">
                        {$v['title']}
                        </a>
                    </li>
ITEM;
        }
        
        
        $this->out .= <<<OUT
                <div class="navbar navbar-inverse">
                    <div class="navbar-inner">
                        <div class="container">
                            <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                                <span class="icon-bar"></span>
                            </button>
                            <div class="nav-collapse collapse">
                                <a target='_blank' style='padding:5px 20px 5px 20px' class="brand" href="{$adminUrl}">{$titleString}</a>
                                <ul class="nav">
                                    {$itemString}
                                </ul>
                            </div><!--/.nav-collapse -->
                        </div>
                    </div>
                </div>
                
OUT;
        if($this->controller == 'site'){
            $this->out .= <<<SITE
                    <header class="jumbotron subhead" id="overview">
                        <div class="container">
                            <h1>{$titleString}</h1>
                            <p class="lead">{$descriptionString}</p>
                        </div>
                    </header>
SITE;
        }
    }
}


